set -x

source var.sh

manual_agenda(){
    crontab -e
}

agenda(){
    keyword=echo
    cmd="echo `date` >>$PWD/log/`date +\"%F_%T\"`.log"

    mkdir -p $PWD/log
    cron_file=`date +"%F_%T"`.cron
    crontab -l > $PWD/log/$cron_file
    sed_file=`date +"%F_%T"`.sed
    cat > $sed_file <<EOF
    sed -i '' /$keyword/d "$PWD/log/$cron_file"
EOF
    source $sed_file
    rm $sed_file
    echo "* * * * * $cmd" >> $PWD/log/$cron_file
    cat $PWD/log/$cron_file
    crontab $PWD/log/$cron_file
}
rm_agenda(){
    keyword=echo
    cmd="echo `date` >>$PWD/log/`date +\"%F_%T\"`.log"

    mkdir -p $PWD/log
    cron_file=`date +"%F_%T"`.cron
    crontab -l > $PWD/log/$cron_file
    sed_file=`date +"%F_%T"`.sed
    cat > $sed_file <<EOF
    sed -i '' /$keyword/d "$PWD/log/$cron_file"
EOF
    source $sed_file
    rm $sed_file
    cat $PWD/log/$cron_file
    crontab $PWD/log/$cron_file
}

stdio(){
    CD=$PWD
    cd $DATAX_BIN

    #python datax.py -r streamreader -w streamwriter
    python datax.py $CD/check.json

    cd $CD
}

mysql2mysql(){
    CD=$PWD
    cd $DATAX_BIN

    end_time=`date +"%s"`
    start_time=$(($end_time - 100000))

    python datax.py $CD/mysql2mysql.json -p "-Dstart_time=$start_time -Dend_time=$end_time"

    cd $CD

}

fake_it(){

    #mysql_database=test
    mysql_database=sample
    sql_file=sys_user.sql

    mysql --host=$mysql_host --user=$mysql_user --password=$mysql_password $mysql_database < $sql_file
}

if [ "$1"=="--check" ]; then
    shift
    $@
    exit
fi
